
import 'package:flutter/material.dart';

/// 扫描线
class LinePainter extends CustomPainter{
  double currentPosition;

  LinePainter(this.currentPosition);

  @override
  void paint(Canvas canvas, Size size) {
    var paint = new Paint();

    paint
      ..style = PaintingStyle.stroke //线
      ..color = Colors.blue
      ..strokeWidth = 1.0;

    canvas.drawLine(Offset(0, currentPosition), Offset(size.width, currentPosition), paint);
  }

  @override
  bool shouldRepaint(LinePainter oldDelegate)=> currentPosition!=oldDelegate.currentPosition;
}

// 四个角
class MyPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    var paint = Paint()
      ..isAntiAlias = true
      ..style = PaintingStyle.stroke //线
      ..color = Colors.blue
      ..strokeWidth = 4.0;


    //左上
    canvas.drawLine(Offset(0, 0), Offset(0, 15), paint);
    canvas.drawLine(Offset(0, 0), Offset(15, 0), paint);

    //右上
    canvas.drawLine(Offset(size.width, 0), Offset(size.width, 15), paint);
    canvas.drawLine(Offset(size.width, 0), Offset(size.width-15,0), paint);


    //左下
    canvas.drawLine(Offset(0,size.height), Offset(0,size.height-15), paint);
    canvas.drawLine(Offset(0, size.height), Offset(15, size.height), paint);

    //右下
    canvas.drawLine(Offset(size.width, size.height), Offset(size.width, size.height-15), paint);
    canvas.drawLine(Offset(size.width, size.height), Offset(size.width-15,size.height), paint);


  }

  //在实际场景中正确利用此回调可以避免重绘开销，本示例我们简单的返回true
  @override
  bool shouldRepaint(CustomPainter oldDelegate) => true;
}